<?php

namespace App\Hospital\Metrics\Examples;

use App\Data\SignData;
use App\Models\FamilyEdu;
use App\Models\HospitalImportBigchild;
use App\Models\HospitalImportChild;
use App\Models\HospitalImportPregn;
use App\Models\HospitalUserFamily;
use App\Models\ImportFamily;
use Dcat\Admin\Admin;

class IndexData
{
    public static function child($hospital_id)
    {
        $today = SignData::childToday($hospital_id);
        $total = SignData::childTotle($hospital_id);
        $sign_total = SignData::childSignTotal($hospital_id);
        $sign_rate = $total>0?ceil(($sign_total/$total)*100)."%":0;

        return [
            'field1' => [
                'num'=>$today,
                'name'=>'今日签约数'
            ],
            'field2' => [
                'num'=>$sign_total,
                'name'=>'签约总数'
            ],
            'field3' => [
                'num'=>$total,
                'name'=>'管辖总数'
            ],
            'field4' => [
                'num'=>$sign_rate,
                'name'=>'签约率'
            ],
        ];
    }

    public static function bigChild($hospital_id)
    {
        $today = SignData::bigChildToday($hospital_id);
        $total = SignData::bigChildTotle($hospital_id);
        $sign_total = SignData::bigChildSignTotal($hospital_id);
        $sign_rate = $total>0?ceil(($sign_total/$total)*100)."%":0;

        return [
            'field1' => [
                'num'=>$today,
                'name'=>'今日签约数'
            ],
            'field2' => [
                'num'=>$sign_total,
                'name'=>'签约总数'
            ],
            'field3' => [
                'num'=>$total,
                'name'=>'管辖总数'
            ],
            'field4' => [
                'num'=>$sign_rate,
                'name'=>'签约率'
            ],
        ];
    }
    public static function preg($hospital_id)
    {
        $today = SignData::pregToday($hospital_id);
        $total = SignData::pregTotle($hospital_id);
        $sign_total = SignData::pregSignTotal($hospital_id);
        $sign_rate = $total>0?ceil(($sign_total/$total)*100)."%":0;

        return [
            'field1' => [
                'num'=>$today,
                'name'=>'今日签约数'
            ],
            'field2' => [
                'num'=>$sign_total,
                'name'=>'签约总数'
            ],
            'field3' => [
                'num'=>$total,
                'name'=>'管辖总数'
            ],
            'field4' => [
                'num'=>$sign_rate,
                'name'=>'签约率'
            ],
        ];
    }

    public static function guide($hospital_id)
    {
        $day = FamilyEdu::query()
            ->where('hospital_id',$hospital_id)
            ->where('created_at',">=",date('Y-m-d',strtotime("-1 day")))
            ->count();
        $month = FamilyEdu::query()
            ->where('hospital_id',$hospital_id)
            ->where('created_at',">=",date('Y-m-d',strtotime("-1 month")))
            ->count();
        $total = FamilyEdu::query()
            ->where('hospital_id',$hospital_id)
            //->where('created_at',">=",date('Y-m-d',strtotime("-1 month")))
            ->count();
        return [
            'field1' => [
                'num'=>$day,
                'name'=>'昨日宣教'
            ],
            'field2' => [
                'num'=>$month,
                'name'=>'最近一月宣教'
            ],
            'field3' => [
                'num'=>$total,
                'name'=>'宣教总数'
            ],
            'field4' => [
                'num'=>$total>0?"100%":0,
                'name'=>'规范化管理率'
            ],
        ];
    }
}
